(function(app) {
    app.controller("content_15_inputCtrl", ["$scope", "myFactory", '$http', '$stateParams', '$state', "$q", '$timeout', '$location', '$ionicHistory', function($scope, myFactory, $http, $stateParams, $state, $q, $timeout, $location, $ionicHistory) {

        //接收参数
        var itemId = $stateParams.changeTypeId; //变更项目ID
        var chdrnum01 = $stateParams.chdrnum01; //保单号
        var chdrcoy = $stateParams.chdrcoy; //保单公司号码
        var searchParam = $stateParams.searchParam;
        var policyData; //保单信息
        var initFlag = false; //检测初始化是否完成标志
        $scope.readFlag = false; //阅读协议标志，默认为false
        $scope.aqjshow = false;
        $scope.eqjshow = true;
        $scope.showAdditional=true;
        $scope.planFlag=true;
        $scope.amountFlag=true;//是否判断保额为空
        var item15BeanListCopy = new Array();
        var item15BeanListSearch = new Array();
        /*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 start*/
        $scope.reasonShow = false;//是否显示减保原因
		/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 end*/
        /********************************************初始化函数begin************************************************/
        //androidH();
        var item = "";
        //先初始化
        var isOneYearCrtFlag = true;
        var taxBenefitRole = ""; //受益人角色
        var taxClientNo = ""; //投保人/受益人客户号
        var policy; //基础信息
        var product = "";
        //初始化查询变更项内容
        $scope.load = function() {
            myFactory.loadingShow(); //显示加载圈
            var token = sessionStorage.getItem("token");
            var timestamp = myFactory.getTimetamp();
            var sfis = "itemId-chdrnum-token-timestamp";
            var signStr = "itemId=" + itemId + "&chdrnum=" + chdrnum01 + "&token=" + token + "&timestamp=" + timestamp; //encodeURI(name)
            var sign = myFactory.hex(signStr);
            $http({
                method: 'GET',
                url: app.domain + 'input/initContentItem.action',
                params: { 'itemId': itemId, 'chdrnum': chdrnum01, 'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp }
            }).then(function successCallback(response) {
                if (response.data.success) {
                	
                    $scope.chdrnum01 = response.data.data.policy.base.chdrnum01;
                    $scope.item15 = response.data.data.modelMap.item15;
                    $scope.prdnameList = response.data.data.modelMap.prdnameList;
                    var length = $scope.item15.item15BeanListSearch.length;
                    for (var i = 0; i < length; i++) {
                    	$scope.item15.item15BeanListSearch[i].amount=$scope.item15.item15BeanListSearch[i].amount.toFixed(2);
                    	$scope.item15.item15BeanListSearch[i].preminum=$scope.item15.item15BeanListSearch[i].preminum.toFixed(2);
                    }
                    isOneYearCrtFlag = response.data.data.modelMap.isOneYearCrtFlag;
                    taxBenefitRole = response.data.data.modelMap.taxBenefitRole;
                    taxClientNo = response.data.data.modelMap.taxClientNo;
                    policy = response.data.data.policy;
                    item = $scope.item15;
                    item15BeanListCopy = $scope.item15.item15BeanList;
                    item15BeanListSearch = $scope.item15.item15BeanListSearch;
                    product = response.data.data.modelMap.product;
                    $scope.showAdditional= response.data.data.modelMap.showAdditional;
                    //当用户返回修改时，需要显示，不然返回清空了 csf 20200814
                    if ($scope.item15.benefit == null || $scope.item15.benefit == undefined) {
                        $scope.item15.benefit = [];
                    }
                    console.log("product:" + product);
                    //product='1';
                    if (product == '2') {
                        isAdd = "O";
                        $scope.showBjqjbxfFlag = false;
                    } else {
                        $scope.showBjqjbxfFlag = true;
                        if (product == '1') {
                            $scope.show23bbjFlag = true; //显示投保人界面
                        }
                    }
                    var length = $scope.item15.benefit.length;
                	if(length > 0){
                	   //$scope.planFlag=true;
                	    $scope.planFlag2=false;
                	}else{
                 	   //$scope.planFlag=false;
                 	    $scope.planFlag2=true;
                	}
                    initFlag = true; //标识初始化成功
                    
                }
                myFactory.loadingHide();
            }, function errorCallback(response) {
                myFactory.loadingHide();
                myFactory.alert("", "初始化查询变更项内容失败!", "info");
            });
        }

        /********************************************初始化函数end************************************************/
        $scope.change = function(index) {
            var options = "";
            var optionselect = "#change15" + index + " option:selected";
            options = $(optionselect);
            var reasonInputIndex = "#reasonInput" + index;
            $(reasonInputIndex).val(options.text());

            $("#change15" + index).val(options.val());
            var change15 = $("#change15" + index).val();
            /*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 start*/
            $scope.item15.item15BeanList[index].operation = change15;
            /*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 end*/
            /*if (change15 =="update" || change15 =="delete") {
            	item15BeanListCopy[index].mainRiskFlag = change15;
            }*/
            if (change15 == "update" || change15 == "delete") {
                item15BeanListCopy[index].operation = change15;
            }
            if (change15 == "update") {
                $("#amount" + index).removeAttr("readonly");
                $("#preminum" + index).removeAttr("readonly");
            } else {
                /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 update by lb 20230418 start*/
                if (change15 == "reset" || change15 == "delete") {
                /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 update by lb 20230418 end*/
                    $scope.item15.item15BeanList[index].preminum = item15BeanListSearch[index].preminum;
                    $scope.item15.item15BeanList[index].amount = item15BeanListSearch[index].amount;
                    $("#amount" + index).val(item15BeanListSearch[index].amount);
                    $("#preminum" + index).val(item15BeanListSearch[index].preminum);
                  
                    var length = $scope.item15.benefit.length;
                	if(length > 0){
                	   //$scope.planFlag=true;
                	    $scope.planFlag2=false;
                	}else{
                		 var length = $scope.item15.item15BeanList.length;
                         var increment = false; //修改后的金额是否增加
                         for (var i = 0; i < length; i++) {
                             if (Number($scope.item15.item15BeanList[i].amount) > Number(item15BeanListSearch[i].amount)
                            		 || Number($scope.item15.item15BeanList[i].preminum) > Number(item15BeanListSearch[i].preminum)) {
                                         increment = true;
                             }
                         }
                        if(increment==true){
                     	   //$scope.planFlag=true;
                     	   $scope.planFlag2=false;
                        } 
                        if(increment==false){
                      	   //$scope.planFlag=false;
                      	   $scope.planFlag2=true;
                        }
                	}
                    
                    
                }
                $("#amount" + index).attr("readonly", "readonly");
                $("#preminum" + index).attr("readonly", "readonly");
            }
            /*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 start*/
            var isreason = false;//是否存在减保
            if (change15 == "delete") {
            	isreason = true;
            }else{
            	 var length = $scope.item15.item15BeanList.length;
                 for (var i = 0; i < length; i++) {
                 	 if(Number($scope.item15.item15BeanList[i].amount) < Number(item15BeanListSearch[i].amount)|| ($scope.item15.item15BeanList[i].operation == "delete" && index!=i)){//减保
                     	 isreason = true;
                      }
                 }
            }
            if(isreason){
           	 	$scope.reasonShow = true;//显示减保原因
            }else{
           	 	$scope.reasonShow = false;//不显示减保原因
            }
            /*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 end*/

        }
        
        //获取input的焦点
        $scope.amountBlur = function(index){
        	var amount="#amount"+index;
        	if($(amount).attr("readonly")=="readonly"){
        		return;
        	}
        	//alert("进入amountBlur处理");
            $scope.item15.item15BeanList[index].amount = $(amount).val();
           // alert("修改后的amount值"+$scope.item15.item15BeanList[e.currentTarget.id.substring(6)].amount);
            var length = $scope.item15.benefit.length;
        	if(length > 0){
        	   //$scope.planFlag=true;
        	    $scope.planFlag2=false;
        	}else{
        		 var length = $scope.item15.item15BeanList.length;
                 var increment = false; //修改后的金额是否增加
                 for (var i = 0; i < length; i++) {
                     if (Number($scope.item15.item15BeanList[i].amount) > Number(item15BeanListSearch[i].amount)
                    		 || Number($scope.item15.item15BeanList[i].preminum) > Number(item15BeanListSearch[i].preminum)) {
                                 increment = true;
                     }
                 }
                if(increment==true){
             	   //$scope.planFlag=true;
             	   $scope.planFlag2=false;
                } 
                if(increment==false){
              	   //$scope.planFlag=false;
              	   $scope.planFlag2=true;
                }
        	}
        	/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 start*/
            var isreason = false;//是否存在减保
            var length = $scope.item15.item15BeanList.length;
            for (var i = 0; i < length; i++) {
                if(Number($scope.item15.item15BeanList[i].amount) < Number(item15BeanListSearch[i].amount) 
               		 || $scope.item15.item15BeanList[i].operation == "delete"){//减保
               	 isreason = true;
                }            
            }
            if(isreason){
           	  $scope.reasonShow = true;//显示减保原因
            }else{
           	  $scope.reasonShow = false;//不显示减保原因
            }
            /*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 end*/
        }
        $scope.preminumBlur = function(index){
        	
        	var preminum="#preminum"+index;
        	if($(preminum).attr("readonly")=="readonly"){
        		return;
        	}
        	//alert("进入preminumBlur处理");
            $scope.item15.item15BeanList[index].preminum = $(preminum).val();
           // alert("修改后的preminum值"+$scope.item15.item15BeanList[e.currentTarget.id.substring(8)].preminum);
            var length = $scope.item15.benefit.length;
         	if(length > 0){
         	   //$scope.planFlag=true;
         	   $scope.planFlag2=false;
         	}else{

       		   var length = $scope.item15.item15BeanList.length;
                var increment = false; //修改后的金额是否增加
                for (var i = 0; i < length; i++) {
                    if (Number($scope.item15.item15BeanList[i].amount) > Number(item15BeanListSearch[i].amount) ||
                    		Number($scope.item15.item15BeanList[i].preminum) > Number(item15BeanListSearch[i].preminum)) {
                                increment = true;
                    }
                }
               if(increment==true){
            	   //$scope.planFlag=true;
            	   $scope.planFlag2=false;
               } 
               if(increment==false){
             	   //$scope.planFlag=false;
             	   $scope.planFlag2=true;
               }
       	
         	}
         
        }
        $scope.data = {
          radioFlag: true
        },
        //单选按钮样式控制
        $scope.isLabel = function() {
            $scope.data.radioFlag = true;
        }
        $scope.notLabel = function() {
            $scope.data.radioFlag = false;
        }

        //重新受理
        $scope.renew = function() {
            var item15_health=sessionStorage.getItem("item15_health");
            if(item15_health == "true"){
                sessionStorage.setItem("item15_health", false);
            }
            var item29_health=sessionStorage.getItem("item29_health");
            if(item29_health == "true"){
                sessionStorage.setItem("item29_health", false);
            }
            var item30_health=sessionStorage.getItem("item30_health");
            if(item30_health == "true"){
                sessionStorage.setItem("item30_health", false);
            }
            myFactory.renew();
        }
        //退出移动保全
        $scope.exit = function() {
        	 var item15_health=sessionStorage.getItem("item15_health");
             if(item15_health == "true"){
                 sessionStorage.setItem("item15_health", false);
             }
             var item29_health=sessionStorage.getItem("item29_health");
             if(item29_health == "true"){
                 sessionStorage.setItem("item29_health", false);
             }
             var item30_health=sessionStorage.getItem("item30_health");
             if(item30_health == "true"){
                 sessionStorage.setItem("item30_health", false);
             }
            myFactory.exit();
        }

        //确定关闭弹窗
        $scope.certainClose = function() {
            var province = $("#province").find("option:selected").text();
            if (province == "请选择") {
                $.alert({ title: '', text: '省/自治区必填！', onOK: function() {} });
                return;
            }
            var city = $("#city").find("option:selected").text();
            if (city == "请选择") {
                $.alert({ title: '', text: '市必填', onOK: function() {} });
                return;
            }
            var district = $("#district").find("option:selected").text();
            var districtOptions = $("#district option");
            if (districtOptions.length > 1) {
                if (district == "请选择") {
                    $.alert({ title: '', text: '区/县必填', onOK: function() {} });
                    return;
                }
            } else {
                district = "";
            }

            var town = $("#town").val();
            var country = $("#country").val();
            var address_a = $("#address_a").val();
            if (address_a == "") {
                $.alert({ title: '', text: '详细地址必填', onOK: function() {} });
                return;
            }
            $("#address").val(province + city + district + town + country + address_a);
            modal('close', 'addrModal', 'addrWindow', 'addrCloseX');
        }

        //取消关闭弹窗
        $scope.cancelClose = function() {
            modal('close');
        }

        //关闭遮罩
        $scope.overwindowClose = function() {
            $(".overwindow").hide();
            $(".overmodal").hide();
        }

        $scope.goBack = function() {
            myFactory.goBack();
        }

        $scope.nextStep = function() {
        	setTimeout(function(){
                var options = $("#change15 option:selected");
                //判断是否初始化完成了，如果失败，不予进入下一步
                if (!initFlag) {
                    myFactory.alert("", "初始化时失败，请返回上一步重试", "info");
                    return false;
                }
                //if($scope.planFlag==true){
	                var readImageFlag = $("#readImageFlag").val();
	                if (readImageFlag == "false") {
	                    myFactory.alert('', "请确定已阅读并同意《投保人/被保险人声明与申请须知》！", 'info');
	                    return;
	                }
                //}

                var sourceFlag = $("#sourceFlag").val();

                if ($scope.showBjqjbxfFlag) {
                    var isAddFlag = $scope.data.radioFlag;
                    isAdd = "Y";
                    if (!isAddFlag) {
                        isAdd = "N";
                    }
                }

                $scope.item15.isAdd = isAdd;

                var length = $scope.item15.item15BeanList.length;
               
                $scope.item15.item15BeanList = [];

                
                
                for (var i = 0; i < length; i++) {
                    var name = item15BeanListCopy[i].name;
                    var amount = $("#amount" + i).val();
                    var preminum = $("#preminum" + i).val();
                    var code = item15BeanListCopy[i].code;
                    var mainRiskFlag = item15BeanListCopy[i].mainRiskFlag;
                    var operation = $("#change15" + i).val();
                    var type = item15BeanListCopy[i].type;
                    var item = {
                        "name": name,
                        "amount": amount,
                        "preminum": preminum,
                        "code": code,
                        "mainRiskFlag": mainRiskFlag,
                        "operation": operation,
                        "type": type
                    }
                    $scope.item15.item15BeanList[i] = item;
                }

            	var nextBeanList=new Array();
                for (var i = 0; i < length; i++) {
                	var operation = $("#change15" + i).val();
                	//判断保费是否是U或者W
                	if(item15BeanListSearch[i].type!="U" && item15BeanListSearch[i].type!="W"){
                		if(operation!="delete"){
		                	 if (Number($scope.item15.item15BeanList[i].amount) !=  Number(item15BeanListSearch[i].amount)) {
		                		 nextBeanList.push($scope.item15.item15BeanList[i]);
		                     }
                		}
	                	 if(operation=="delete"){
	                		 nextBeanList.push($scope.item15.item15BeanList[i]);
	                	 }
	               	 }else{
	               		if(operation!="delete"){
		               		 if (Number($scope.item15.item15BeanList[i].amount) !=  Number(item15BeanListSearch[i].amount)
			                     		|| Number($scope.item15.item15BeanList[i].preminum) != Number(item15BeanListSearch[i].preminum)) {
		               			 nextBeanList.push($scope.item15.item15BeanList[i]);
			                 }
	               		}
	               	  	 if(operation=="delete"){
	                		 nextBeanList.push($scope.item15.item15BeanList[i]);
	                	 }
	               	 }
                }
                $scope.item15.item15BeanListSave=nextBeanList;
              //判读数据更改过数据
                var dataChange=false;
                for (var i = 0; i < length; i++) {
                	var operation = $("#change15" + i).val();
                	 if(item15BeanListSearch[i].type!="U" && item15BeanListSearch[i].type!="W"){
                		 if(operation=="update"){
		                	 if (Number($scope.item15.item15BeanList[i].amount) ==  Number(item15BeanListSearch[i].amount)) {
		                		 myFactory.alert("","险种【"+item15BeanListSearch[i].name+"】未有修改，请确认！","info");
		                		 return false;
		                     }else{
		                    	 dataChange=true;
	                		 }
                		 }
                	 }else{
                		 if(operation=="update"){
	                		 if (Number($scope.item15.item15BeanList[i].amount) ==  Number(item15BeanListSearch[i].amount)
	 	                     		&& Number($scope.item15.item15BeanList[i].preminum) == Number(item15BeanListSearch[i].preminum)) {
	                			 myFactory.alert("","险种【"+item15BeanListSearch[i].name+"】未有修改，请确认！","info");
	                			 return false;
	 	                     }else{
	 	                    	dataChange=true;
	 	                     }
                		 }
                	 }
                	 if(operation=="delete" || operation=="reset"){
            			 dataChange=true;
                	 }else{
                		 if($scope.item15.item15BeanList[i].amount==""){
                			 myFactory.alert("", "请输入保额金额", "info");
                			 return;
                		 }
	             		 if($scope.item15.item15BeanList[i].type=="U" || $scope.item15.item15BeanList[i].type=="W"){
	             			 if($scope.item15.item15BeanList[i].preminum==""){
	             				myFactory.alert("", "请输入保费金额", "info");
	                			return;
	             			 }
	             		 }
                	 }
                }
                if($scope.item15.benefit.length>0){
                	dataChange=true;
                }
                if(!dataChange){
                    myFactory.alert("", "未输入保险计划变更内容", "info");
                    return false;
                }
                
                /*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 start*/
                if($scope.reasonShow){
                	var reasonInput = $("#reasonInput").val();
    			    var reason = $("#reasonSelect option:selected").val(); //减保原因
    			    if(reason==null || reason == ""){
    			    	myFactory.alert("","请选择减保原因!","info");
    					return false;
    			    }else{
    			    	$scope.item15.reason = reason;
    			    }
                }else{
                	$scope.item15.reason = "";
                }
                /*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 end*/
                
                $scope.item15.contentXml = "";
                $scope.item15.remark = "";
                var item15 = $scope.item15;
                //寿险判断有没有新增的附加险，有直接下一步
                var sx = $scope.item15.benefit;
                if (null != sx && undefined != sx && sx.length > 0) {
                    $scope.item15.sourceFlag = sourceFlag;
                    sessionStorage.setItem("changeItem15_increment", true);
                    $ionicHistory.clearCache().then(function() {
                        $state.go('content_15_common', {
                            itemId: "15",
                            chdrnum01: chdrnum01,
                            chdrcoy: chdrcoy,
                            item15: item15
                        });
                    })
                } else {
                    var length = $scope.item15.item15BeanList.length;
                    var ischange = false; //是否是修改了
                    var increment = false; //修改后的金额是否增加
                    //金额如果是减少状态，则直接下一步，增加状态才进告知
                    for (var i = 0; i < length; i++) {
                        if ($("#change15" + i).val() != "reset") {
                            //判断金额增加还是减少
                            if ($("#change15" + i).val() == "update") {
                                //if(item15BeanListCopy[i].amount < $scope.item15.item15BeanList[i].amount || item15BeanListCopy[i].preminum < $scope.item15.item15BeanList[i].preminum){
                                if (Number($scope.item15.item15BeanList[i].amount) > Number(item15BeanListSearch[i].amount)
                                		|| Number($scope.item15.item15BeanList[i].preminum) > Number(item15BeanListSearch[i].preminum)) {

                                    increment = true;
                                }
                            }
                            ischange = true;
                        }
                    }
                    if (ischange && increment) {
                    	sessionStorage.setItem("changeItem15_increment", true);
                        $scope.item15.sourceFlag = sourceFlag;
                        $ionicHistory.clearCache().then(function() {
                            $state.go('content_15_common', {
                                itemId: "15",
                                chdrnum01: chdrnum01,
                                chdrcoy: chdrcoy,
                                item15: item15
                            });
                        })
                    }
                    if (ischange && !increment) {
                        $scope.item15.sourceFlag = "2";
                        var item = $scope.item15;
                        sessionStorage.setItem("changeItem15_increment", false);
                        $ionicHistory.clearCache().then(function() {
                            $state.go('content_check_main', {
                                itemId: "15",
                                item: item,
                                chdrnum01: chdrnum01,
                                chdrcoy: chdrcoy,
                            });
                        })
                    }
                    if (!ischange) {
                        alert("未输入保险计划变更内容");
                    }

                }
              },250);
            }
        //新增弹窗
        $scope.newRadio = function(type) {
            if (type == 1) {
                $scope.NewPopSexFlag = false;
                $scope.aqjshow = true;
                $scope.newRadioYFlag=true;
                $scope.newRadioNFlag=false;
            } else if (type == 2) {
                $scope.NewPopSexFlag = true;
                $scope.aqjshow = false;
                $scope.newRadioYFlag=false;
                $scope.newRadioNFlag=true;
            }
        }
        //新增
        $scope.addPeopleModelShow = function() {
            $.showLoading('正在处理,请稍候');
            setTimeout(function() {
                $.hideLoading();
            }, 300);

            /**
             * 数据初始化
             */
            $("#xzNameInput").val("");
            $("#beInput").val("");
            $("#qbfInput").val("");
            $scope.NewPopSexFlag = false;
            $scope.aqjshow = false;
            $scope.newRadioYFlag = false;
            $scope.newRadioNFlag = false;
            $scope.amountFlag=true;
            /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 start*/
            $scope.insurPeriodShow = false;
            $scope.payPeriodShow = false;
            $scope.period1Flag = false;
            $scope.period2Flag = false;
            $scope.payType1Flag = false;
            $scope.payType2Flag = false;
            $("#periodAge").attr("disabled", true).val('');
            $("#periodYear").attr("disabled", true).val('');
            $("#payYear").attr("disabled", true).val('');
            $("#payAge").attr("disabled", true).val('');
            /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 end*/

            modal('open', 'addPeopleModal', 'overwindowOn15Input', 'addPeopleModalCloseX');

        }

        //新增受益人关闭弹窗
        $scope.addPeopleCancel = function() {
            /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 start*/
            $scope.insurPeriodShow = false;
            $scope.payPeriodShow = false;
            /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 end*/
        	$("#xzNameDiv").html('');
    	    $("#xzNameInput").css('display','inline');
            modal('close', 'addPeopleModal', 'overwindowOn15Input', 'addPeopleModalCloseX');
        }

        //确定添加
        $scope.addPeopleComfirm = function() {
            /**
             * 获取数据
             */

            var xzNameInput = $("#xzNameInput").val();
            var beInput = $("#beInput").val();
            var qbfInput = $("#qbfInput").val();
            var typeRisk;
            if ($scope.NewPopSexFlag == false) {
                typeRisk = "0";
            } else {
                typeRisk = "1";
            }
            if (xzNameInput == null || xzNameInput.trim() == "") {
                myFactory.alert("", "险种名称不能为空", "info");
                return;
            }
            if($scope.amountFlag){
            	if (beInput == null || beInput.trim() == "") {
                    //myFactory.alert("", "保额不能为空", "info");
                	$scope.amountModalOpen();
                    return;
                }else if(beInput<1){
                	myFactory.alert("", "保额不能小于1", "info");
                    return;
                }
            }
            if($scope.newRadioYFlag==false && $scope.newRadioNFlag==false){
            	myFactory.alert("", "请选择是否投连万能险", "info");
                return;
            }
            if (typeRisk == "0") {
                if (qbfInput == null || qbfInput.trim() == "") {
                    myFactory.alert("", "期缴保险费不能为空", "info");
                    return;
                }else if(qbfInput<1){
                	myFactory.alert("", "期缴保险费不能小于1", "info");
                    return;
                }
            }
            /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 start*/
            var insurPeriodType = '' // 保险期类型
            var insurPeriod = ''; // 保险期
            var payPeriodType = ''; // 缴费期类型
            var payPeriod = ''; // 缴费期
            if ($scope.insurPeriodShow) {
                // 获取输入的保险期
                if(!$scope.period1Flag && !$scope.period2Flag){
                    myFactory.alert("", "请选择保险期类型", "info");
                    return;
                } else if ($scope.period1Flag) {
                    insurPeriodType = '1';
                    insurPeriod = $("#periodYear").val();
                } else if ($scope.period2Flag) {
                    insurPeriodType = '2';
                    insurPeriod = $("#periodAge").val();
                }
                if (insurPeriod == '') {
                    myFactory.alert("", "请输入保险期", "info");
                    return;
                }
            }
            if ($scope.payPeriodShow) {
                // 获取输入的缴费期
                if(!$scope.payType1Flag && !$scope.payType2Flag){
                    myFactory.alert("", "请选择缴费期类型", "info");
                    return;
                } else if ($scope.payType1Flag) {
                    payPeriodType = '1';
                    payPeriod = $("#payYear").val();
                } else if ($scope.payType2Flag) {
                    payPeriodType = '2';
                    payPeriod = $("#payAge").val();
                }
                if (payPeriod == '') {
                    myFactory.alert("", "请输入缴费期", "info");
                    return;
                }
            }

            var item = {
                "riskname": xzNameInput,
                "riskamount": beInput,
                "riskpremium": qbfInput,
                "typeRisk": typeRisk,
                "insurPeriodType": insurPeriodType,
                "insurPeriod": insurPeriod,
                "payPeriodType": payPeriodType,
                "payPeriod": payPeriod
            }
            $scope.insurPeriodShow = false;
            $scope.payPeriodShow = false;
            /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 end*/
            $scope.item15.benefit.push(item);
            //$scope.planFlag=true;
    	    $scope.planFlag2=false;
    	    $("#xzNameDiv").html('');
    	    $("#xzNameInput").css('display','inline');
            modal('close', 'addPeopleModal', 'overwindowOn15Input', 'addPeopleModalCloseX');
        }
        //编辑受益人弹窗 性别单选按钮样式控制
        $scope.editPopSex = function(type) {
            if (type == 1) {
                $scope.EditPopSexFlag = false;
                $scope.eqjshow = true;
            } else if (type == 2) {
                $scope.EditPopSexFlag = true;
                $scope.eqjshow = false;
            }
            console.log(type);
            console.log($scope.EditPopSexFlag);
        }
        //编辑受益人
        $scope.changeBenefit = function(index) {
            $.showLoading('正在处理,请稍候');
            setTimeout(function() {
                $.hideLoading();
            }, 300);

            console.log(index);
            modal('open', 'editPeopleModal', 'overwindowOn15Input', 'editPeopleModalCloseX');
            /**
             * 数据加载
             */
            var item = $scope.item15.benefit[index]; //关于这里，只要从数据点击编辑跳过来的，则一定会有数据

            $("#benfTypeEdit").val(item.benfType);
            $("#editNo").val(index); //表明当前操作的元素是第几个

            $("#xzNameEdit").val(item.riskname);
            $("#xzNameEditDiv").html(item.riskname);
            $("#beEdit").val(item.riskamount);
            $("#qbfEdit").val(item.riskpremium);

            //加载是否投连/万能险
            if (item.typeRisk == "0") {
                $scope.EditPopSexFlag = false;
                $scope.eqjshow = true;
            } else {
                $scope.EditPopSexFlag = true;
                $scope.eqjshow = false;
            }
            /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 start*/
            if (item.insurPeriodType != '') {
                $scope.insurPeriodShow = true;
                if (item.insurPeriodType == '1') {
                    $scope.editPeriod1Flag = true;
                    $("#editPeriodYear").val(item.insurPeriod);
                    $("#editPeriodAge").attr("disabled", true);
                } else {
                    $scope.editPeriod2Flag = true;
                    $("#editPeriodAge").val(item.insurPeriod);
                    $("#editPeriodYear").attr("disabled", true);
                }
            } else {
                $scope.insurPeriodShow = false;
            }
            if (item.payPeriodType != '') {
                $scope.payPeriodShow = true;
                if (item.payPeriodType == '1') {
                    $scope.editPayType1Flag = true;
                    $("#editPayYear").val(item.payPeriod);
                    $("#editPayAge").attr("disabled", true);
                } else {
                    $scope.editPayType2Flag = true;
                    $("#editPayAge").val(item.payPeriod);
                    $("#editPayYear").attr("disabled", true);
                }
            } else {
                $scope.payPeriodShow = false;
            }
            /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 end*/
        }
        //编辑保险计划关闭弹窗
        $scope.editPeopleCancel = function() {
        	$("#xzNameEdit").html('');
            /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 start*/
            $scope.cleanEditWindowData(); // 清除编辑框中的内容，避免编辑其他险种信息时数据展示错误
            /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 end*/
      	    $("#xzNameEditDiv").css('display','inline');
            modal('close', 'editPeopleModal', 'overwindowOn15Input', 'editPeopleModalCloseX');
        }

        $scope.editPeopleComfirm = function() {
            /**
             * 获取数据
             */
            var name = $("#xzNameEdit").val(); //名字
            var be = $("#beEdit").val();
            var qbf = $("#qbfEdit").val();
            var typeRisk;
            if ($scope.EditPopSexFlag == false) {
                typeRisk = "0";
            } else {
                typeRisk = "1";
            }
            
        	if (be == null || be.trim() == "") {
                //myFactory.alert("", "保额不能为空", "info");
        		//return;
            }else if(be<1){
            	myFactory.alert("", "保额不能小于1", "info");
                return;
            }

            if (typeRisk == "0") {
                if (qbf == null || qbf.trim() == "") {
                    myFactory.alert("", "期缴保险费不能为空", "info");
                    return;
                }else if(qbf<1){
                	myFactory.alert("", "期缴保险费不能小于1", "info");
                    return;
                }
            }
            /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 start*/
            var insurPeriodType = '' // 保险期类型
            var insurPeriod = ''; // 保险期
            var payPeriodType = ''; // 缴费期类型
            var payPeriod = ''; // 缴费期
            if ($scope.insurPeriodShow) {
                // 获取输入的保险期
                if(!$scope.editPeriod1Flag && !$scope.editPeriod2Flag){
                    myFactory.alert("", "请选择保险期类型", "info");
                    return;
                } else if ($scope.editPeriod1Flag) {
                    insurPeriodType = '1';
                    insurPeriod = $("#editPeriodYear").val();
                } else if ($scope.editPeriod2Flag) {
                    insurPeriodType = '2';
                    insurPeriod = $("#editPeriodAge").val();
                }
                if (insurPeriod == '') {
                    myFactory.alert("", "请输入保险期", "info");
                    return;
                }
            }
            if ($scope.payPeriodShow) {
                // 获取输入的缴费期
                if(!$scope.editPayType1Flag && !$scope.editPayType2Flag){
                    myFactory.alert("", "请选择缴费期类型", "info");
                    return;
                } else if ($scope.editPayType1Flag) {
                    payPeriodType = '1';
                    payPeriod = $("#editPayYear").val();
                } else if ($scope.editPayType2Flag) {
                    payPeriodType = '2';
                    payPeriod = $("#editPayAge").val();
                }
                if (payPeriod == '') {
                    myFactory.alert("", "请输入缴费期", "info");
                    return;
                }
            }
            var item = {
                "riskname": name,
                "riskamount": be,
                "riskpremium": qbf,
                "typeRisk": typeRisk,
                "insurPeriodType": insurPeriodType,
                "insurPeriod": insurPeriod,
                "payPeriodType": payPeriodType,
                "payPeriod": payPeriod
            }
            // 清除编辑框中的内容，避免编辑其他险种信息时数据展示错误
            $scope.cleanEditWindowData();
            /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 end*/
            var index = $("#editNo").val(); //得到当前操作的元素是第几个

            $scope.item15.benefit[index] = item; //将所操作的对象数据进行调整
            $("#xzNameEdit").html('');
    	    $("#xzNameEditDiv").css('display','inline');
            modal('close', 'editPeopleModal', 'overwindowOn15Input', 'editPeopleModalCloseX'); //关闭弹框
        }
        
        $scope.crtableListModalOpen = function(type) {
        	$scope.prdnameType = type;
        	modal('open', 'crtableListModal', 'crtableListModalOverwindow', 'crtableListModalCloseX');
        };
        
        $scope.otherZD = function() {
        	$("#crtableListModal").css("top","28%");
        };
        
        $scope.openCrtableInput = function() {
        	$("#otherPrdname").css("display","inline");
        };
        
        //关闭遮罩
        $scope.crtableListModalOverwindowClose = function() {
            $("#crtableListModalOverwindow").hide();
            $("#crtableListModal").hide();
        }
        
        $scope.crtableListModalCancel = function() {
        	$("#crtableListModal").css("top","50%");
        	$("#otherPrdname").css("display","none");
        	$('input:radio[name=prdname_radio]').attr('checked',false);
            $("#otherPrdname").val("");
            modal('close', 'crtableListModal', 'crtableListModalOverwindow', 'crtableListModalCloseX');
        }
        
        $scope.cleatOther= function(){
        	$("#crtableListModal").css("top","50%");
        	$("#otherPrdname").val("");
        }
        
        $scope.otherPrdname = function() {
            var otherPrdname = $("#otherPrdname").val();
            if (otherPrdname != null && otherPrdname.trim() != "") {
            	$("input:radio[name='prdname_radio']").attr("checked",false);
            }
        }
        
        $scope.crtableListModalComfirm = function() {
        	$("#crtableListModal").css("top","50%");
        	var prdname;
        	var otherPrdname = $("#otherPrdname").val();
            if (otherPrdname != null && otherPrdname.trim() != "") {
            	prdname = otherPrdname;
            }else{
            	prdname = $("input:radio[name='prdname_radio']:checked").val();
            }
            if(prdname==null || prdname.trim() == "" || prdname == undefined){
            	 myFactory.alert("", "请选择或输入险种名称", "info");
                 return;
        	}else{
        		var length = $scope.item15.item15BeanList.length;
            	for (var i = 0; i < length; i++) {
                    if ($scope.item15.item15BeanList[i].name==prdname) {
                    	myFactory.alert("","所选附加险重复，请确认！","info");
                    	return;
                    }
                }
            	var newlength = $scope.item15.benefit.length;
            	for (var i = 0; i < newlength; i++) {
                    if ($scope.item15.benefit[i].riskname==prdname) {
                    	myFactory.alert("","所选附加险重复，请确认！","info");
                    	return;
                    }
                }

                /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 start*/
                var paramsMap = {
                    prdName: prdname,
                    chdrnum: chdrnum01
                }
                var token = sessionStorage.getItem("token");
                var timestamp = myFactory.getTimetamp();
                var sfis = "token-timestamp";
                var signStr = "token=" + token + "&timestamp=" + timestamp;
                var sign = myFactory.hex(signStr);
                $http({
                    method: 'POST',
                    url: app.domain + 'query/getFlagByPrdName.action',
                    data: { paramsMap: paramsMap,'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp }
                }).then(function successCallback(response) {
                    if (response.data.success) {
                        if (response.data.data.notOpt == '1') {
                            myFactory.alert("", "该险种与主险类型不匹配", "info");
                            return;
                        }
                        $scope.payPeriodShow = response.data.data.payFlag == '0';
                        $scope.insurPeriodShow = response.data.data.insurFlag == '0';
                    }
                }, function errorCallback(response) {
                    myFactory.alert("", "获取‘缴费期’‘保险期’标志失败!", "info");
                });
                /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 end*/

                if($scope.prdnameType=="1"){
                    $("#xzNameInput").val(prdname);
                    $("#xzNameDiv").html(prdname);
                    $("#xzNameInput").css('display','none');
                }else{
                    $("#xzNameEdit").val(prdname);
                    $("#xzNameEditDiv").html(prdname);
                    $("#xzNameEdit").css('display','none');
                }
        	}
            $("#otherPrdname").css("display","none");
            $('input:radio[name=prdname_radio]').attr('checked',false);
            $("#otherPrdname").val("");
            
    	    modal('close', 'crtableListModal', 'crtableListModalOverwindow', 'crtableListModalCloseX');
        }
        /*******************************************************编辑受益人部分start***************************************************/
        //删除
        $scope.deleteBenefit = function(index) {
            var afterDetele = [];
        
            for (var i = 0; i < $scope.item15.benefit.length; i++) {
                if (i != index) {
                    afterDetele.push($scope.item15.benefit[i]); //如果不为空，放入处理后数组
                }
            }
            $scope.item15.benefit = afterDetele; //最后将数组替换item08.benefit即可，最后数据提交也提交这个即可
            
            var length = $scope.item15.benefit.length;
            if(length==0){
                var length = $scope.item15.item15BeanList.length;
                var increment = false; //修改后的金额是否增加
                //金额如果是减少状态，则直接下一步，增加状态才进告知
                for (var i = 0; i < length; i++) {
                       
                            if (Number($scope.item15.item15BeanList[i].amount) > Number(item15BeanListSearch[i].amount)
                            		|| Number($scope.item15.item15BeanList[i].preminum) > Number(item15BeanListSearch[i].preminum)) {

                                increment = true;
                            }
                        
                }
                if(increment==true){
                	//$scope.planFlag=true;
               	    $scope.planFlag2=false;
                }else{
                	//$scope.planFlag=false;
               	    $scope.planFlag2=true;
                }
            }
        }

        //弹出弹窗
        $scope.chooseAttr = function() {
            var address = $("#address").val();
            modal('open', 'addrModal', 'addrWindow', 'addrCloseX');
            if (!flag) {
                clearAddress();
                initAddr(address);
            }
        }


        $scope.adCancel = function() {
            modal('close', 'addrModal', 'addrWindow', 'addrCloseX');
            if (!flag) {
                clearAddress();
            }
        }

        //保单详情弹窗
        $scope.showPolicyDetail = function() {
            modal('open', 'policyModalOn15Input', 'overwindowOn15Input', 'policyCloseXOn15Input');
            var token = sessionStorage.getItem("token");
            var timestamp = myFactory.getTimetamp();
            var sfis = "chdrnum-chdrcoy-token-timestamp";
            var signStr = "chdrnum=" + chdrnum01 + "&chdrcoy=" + chdrcoy + "&token=" + token + "&timestamp=" + timestamp; //encodeURI(name)
            var sign = myFactory.hex(signStr);
            //初始化查询订单详情
            $http({
                method: 'GET',
                url: app.domain + 'query/restFindPolicyDetail.action',
                params: { 'chdrnum': chdrnum01, 'chdrcoy': chdrcoy, 'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp }
            }).then(function successCallback(response) {
                if (response.data.success) {
                    $scope.policyData = response.data.data;
                    $scope.policyData.ptdate01 = myFactory.DateTools($scope.policyData.ptdate01);
                }
            }, function errorCallback(response) {
                myFactory.alert("", "初始化查询订单详情失败!", "info");
            });
        }

        //保单详情弹窗关闭函数
        $scope.policyCancelOn15Input = function() {
            modal('close', 'policyModalOn15Input', 'overwindowOn15Input', 'policyCloseXOn15Input');
        }

        $scope.exitTest = function() {
            window.location.href = '../index.html';
        }

        //客户须知弹框
        $scope.tipOpen = function() {
            modal('open', 'tip_model', 'overwindowOn15Input');
        }
        $scope.closeTip = function() {
            modal('close', 'tip_model', 'overwindowOn15Input');
        }
        //页面同意阅读协议复选框部分
        $scope.changeReadFlag = function() {
            $scope.readFlag = !$scope.readFlag;
        }
        
        
        $scope.amountModalOpen = function() {
        	modal('open', 'amountModal', 'amountModalOverwindow', 'amountModalCloseX');
        };
        
        //关闭遮罩
        $scope.amountModalOverwindowClose = function() {
            $("#amountModalOverwindow").hide();
            $("#amountModal").hide();
        }

        $scope.amountModalCancel = function() {
        	$scope.amountFlag=false;
        	$scope.addPeopleComfirm();
            modal('close', 'amountModal', 'amountModalOverwindow', 'amountModalCloseX');
        }
        
        $scope.amountModalComfirm = function() {
        	$scope.amountFlag=true;
        	modal('close', 'amountModal', 'amountModalOverwindow', 'amountModalCloseX');
        }
        
        /*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 start*/
		$scope.changeReason = function(){
			var options = "";
			options =$("#reasonSelect option:selected");
			$scope.reasonInput = options.text();
		}
		/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 end*/

        /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 start*/
        $scope.changePeriod = function (type) {
            if (type === 1) {
                $scope.period1Flag = true;
                $scope.period2Flag = false;
                $("#periodAge").attr("disabled", true).val('')
                $("#periodYear").attr("disabled", false)
            } else {
                $scope.period1Flag = false;
                $scope.period2Flag = true;
                $("#periodYear").attr("disabled", true).val('')
                $("#periodAge").attr("disabled", false)
            }
        }
        $scope.editChangePeriod = function (type) {
            if (type === 1) {
                $scope.editPeriod1Flag = true;
                $scope.editPeriod2Flag = false;
                $("#editPeriodAge").attr("disabled", true).val('')
                $("#editPeriodYear").attr("disabled", false)
            } else {
                $scope.editPeriod1Flag = false;
                $scope.editPeriod2Flag = true;
                $("#editPeriodYear").attr("disabled", true).val('')
                $("#editPeriodAge").attr("disabled", false)
            }
        }
        $scope.changePayType = function (type) {
            if (type === 1) {
                $scope.payType1Flag = true;
                $scope.payType2Flag = false;
                $("#payAge").attr("disabled", true).val('')
                $("#payYear").attr("disabled", false)
            } else {
                $scope.payType1Flag = false;
                $scope.payType2Flag = true;
                $("#payYear").attr("disabled", true).val('')
                $("#payAge").attr("disabled", false)
            }
        }
        $scope.editChangePayType = function (type) {
            if (type === 1) {
                $scope.editPayType1Flag = true;
                $scope.editPayType2Flag = false;
                $("#editPayAge").attr("disabled", true).val('')
                $("#editPayYear").attr("disabled", false)
            } else {
                $scope.editPayType1Flag = false;
                $scope.editPayType2Flag = true;
                $("#editPayYear").attr("disabled", true).val('')
                $("#editPayAge").attr("disabled", false)
            }
        }
        $scope.cleanEditWindowData = function () {
            $scope.insurPeriodShow = false;
            $scope.payPeriodShow = false;
            $scope.editPeriod1Flag = false;
            $scope.editPeriod2Flag = false;
            $scope.editPayType1Flag = false;
            $scope.editPayType2Flag = false;
            $("#editPeriodYear").val('');
            $("#editPeriodAge").val('');
            $("#editPayYear").val('');
            $("#editPayAge").val('');
        }
        /*S2023011624867官微、移动保全增加保险计划变更增加“保险期”录入栏位需求 add by lb 20230418 end*/
    }]);

    //指针弹窗
    app.directive('infoid', function() {
        return {
            restrict: 'EA', //指明指令在DOM里面以什么形式被声明,EA.表示即可以是元素也可以是属性
            templateUrl: 'html/input/content_base_info.html' + app.clearCache,
            replace: true, //设置解析后，DOM声明的指令是否消失
            link: function(scope, element, attrs) { //链接函数负责注册DOM事件和更新DOM,
                console.log('指令完成');
            }
        }
    });
})(app)